<!DOCTYPE html>
<html>
<head>
    <title>角色列表</title>
    <#include "/common/import.ftl" >
    <script>
        var orgId = "${loginUser.orgId!''}";
        $(function () {
            $('#roleList').datagrid({
                title: '角色列表',
                iconCls: 'icon-ok',
                url: '${ctx}/uct/role/role!data.action?orgId=${orgId!""}',
                loadMsg: '数据载入中，请稍后……',
                nowrap: false,
                striped: true,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [10, 15, 20, 50],
                idField: 'roleId',
                columns: [[
                    {
                        field: 'roleCname', title: '角色名称', width: 100, sortable: true,
                        sorter: function (a, b) {
                            return (a > b ? 1 : -1);
                        },
                        formatter: function (value) {
                            return '<a herf="#" onClick="alert(' + value + ');">' + value + '</a>';
                        }
                    },
                    {
                        field: 'roleEname', title: '角色标识', width: 100, sortable: true,
                        sorter: function (a, b) {
                            return (a > b ? 1 : -1);
                        }
                    },
                    {
                        field: 'roleRemark', title: '所属机构', width: 100, sortable: true,
                        formatter: function (value) {
                            if (value) {
                                return value;
                            } else {
                                return "- -";
                            }
                        }
                    },
                    {
                        field: 'createUser', title: '创建人', width: 100, sortable: true,
                        sorter: function (a, b) {
                            return (a > b ? 1 : -1);
                        }
                    },
                    {
                        field: 'createTime', title: '创建时间', width: 100, sortable: true,
                        sorter: function (a, b) {
                            return (a > b ? 1 : -1);
                        },
                        formatter: function (value) {
                            return getSmpFormatDateByLong(value, true);
                        }
                    }
                ]],
                toolbar: [
                    {
                        text: '增加',
                        iconCls: 'icon-add',
                        handler: function () {
                            saveRole('add');
                        }
                    },
                    '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            saveRole('edit');
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-cut',
                        handler: function () {
                            delRole();
                        }
                    }, '-',
                    {
                        text: '刷新',
                        iconCls: 'icon-reload',
                        handler: function () {
                            reload();
                        }
                    }, '-',
                    {
                        text: '资源设置',
                        iconCls: 'icon-rights',
                        handler: function () {
                            roleAct();
                        }
                    }
                ],
                onDblClickRow: function (row) {
                    saveRole('edit');
                }
            });

            var p = $('#roleList').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    onBeforeRefresh: function () {
                        //alert('before refresh');
                    }
                });
            }
        });

        function reload() {
            $('#roleList').datagrid('reload');
        }

        function closeAdd() {
            $('#roleAddWin').window('close');
        }

        function searchRole() {
            var queryParams = $('#roleList').datagrid('options').queryParams;
            queryParams.roleCname = $('#roleCname').val();
            $('#roleList').datagrid("reload");
            $('#query').window('close');
        }

        function saveRole(paraFlag) {
            $('#roleAddFrame').html('');
            var url = '${ctx}/uct/role/add.action?orgParam=${orgId!""}&orgId=' + orgId;
            if ('edit' == paraFlag) {
                var node = getSelected();
                if (node) {
                    url = '${ctx}/uct/role/add.action?roleId=' + node.roleId + '&orgId=' + orgId;
                    $('#roleAddFrame').attr("src", url);
                    $('#roleAddWin').window('open');
                }
            } else {
                $('#roleAddFrame').attr("src", url);
                $('#roleAddWin').window('open');
            }
        }

        function getSelected() {
            var selected = $('#roleList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        function delRole() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color="red">' + node.roleCname + '</font> ？', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/uct/role/del.action?id=" + node.roleId,
                            success: function (data, textStatus) {
                                var result = jQuery.parseJSON(data);
                                if (result.flag == "T") {
                                    $.messager.alert('结果', '操作成功', 'info');
                                    var rowIndex = $('#roleList').datagrid('getRowIndex', node);
                                    $('#roleList').datagrid('deleteRow', rowIndex);
                                    reload();
                                } else {
                                    $.messager.alert('提交结果', result.msg, 'error');
                                }
                            }
                        });
                    }
                });
            }
        }

        function roleAct() {
            var node = getSelected();
            if (node) {
                var widthcount = $(document.body).width() - 20;
                var leftcount = document.documentElement.scrollLeft;
                var url = "role-act.action?roleId=" + node.roleId;
                $('#roleActWin').css({"width": widthcount, "height": "450px", "left": leftcount});
                $('#roleActFrame').attr("src", url);
                $('#roleActWin').window('open');
            }
        }

    </script>
</head>
<body>


<!-- 角色列表 -->
<table id="roleList"></table>

<div id="roleAddWin" class="easyui-window" title="角色设置"
     style="padding:5px;width:500px;height:250px;overflow: hidden;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe frameborder="0" id="roleAddFrame" height="100%" width="100%" scrolling="yes"
            frameborder="0"></iframe>
</div>
<div id="roleActWin" class="easyui-window" title="角色分配资源"
     style="padding:5px;float:left;top:10px;overflow: hidden;" iconCls="icon-search" closed="true"
     minimizable="false" maximizable="false" maximized="true" collapsible="false">
    <iframe frameborder="0" id="roleActFrame" height="100%" width="100%" scrolling="yes"
            frameborder="0"></iframe>
</div>

</body>
</html>